nclude"BTree.h"
#include<stdio.h>
#include<malloc.h>
#include<assert.h>

QNode* buyNode(QDataType data) {
	QNode* newNode = (QNode*)malloc(sizeof(QNode));
	if (NULL == newNode) {
		assert(0);
	}
	newNode->data = data;
	newNode->next = NULL;
	return newNode;
}
//初始化队列
void QueueInit(Queue* q) {
	assert(q);
	q->back = q->front = NULL;
	q->size = 0;

}
// 队尾入队列 
void QueuePush(Queue* q, QDataType data) {
	assert(q);
	QNode* newNode = buyNode(data);
	if (q->front == NULL) {
		q->front = newNode;
	}
	else {
		q->back->next = newNode;
	}
	q->back = newNode;
	q->size++;
}
// 队头出队列 
void QueuePop(Queue* q) {
	assert(q);
	if (QueueEmpty(q)) {
		return 0;
	}
	else {
		q->front = q->front->next;
	}
	q->size--;
}
// 获取队列头部元素 
QDataType QueueFront(Queue* q) {
	assert(q);
	assert(!QueueEmpty(q));
	return q->front->data;
}

// 检测队列是否为空，如果为空返回非零结果，如果非空返回0 
int QueueEmpty(Queue* q) {
	assert(q);
	if (q->size == 0) {
		return 1;
	}
	else {
		return 0;
	}
}
// 销毁队列 
void QueueDestroy(Queue* q) {
	assert(q);
	QNode* cur = q->front;
	while (cur) {
		q->front = cur->next;
		free(cur);
		cur = q->front;
	}
	q->front = q->back = NULL;
	q->size = 0;
}
